using System;
using Volo.Abp.MultiTenancy;
using Matrix.Notification.Domain.Shared.Notifications;
using Matrix.Notification.Domain.Notifications;

namespace Matrix.Notification.Domain.Events
{
    /// <summary>
    /// 通知创建事件
    /// </summary>
    public class NotificationCreatedEto
    {
        public Guid Id { get; set; }
        public Guid? TenantId { get; set; }
        public string Title { get; set; } = string.Empty;
        public string Content { get; set; } = string.Empty;
        public Domain.Shared.Notifications.NotificationType Type { get; set; }
        public Domain.Shared.Notifications.NotificationPriority Priority { get; set; }
        public Domain.Shared.Notifications.NotificationChannel Channel { get; set; }
        public Guid? RecipientId { get; set; }
        public string? RecipientEmail { get; set; }
        public string? RecipientPhoneNumber { get; set; }
        public Guid? SenderId { get; set; }
        public string? SenderName { get; set; }
        public Guid? TemplateId { get; set; }
        public string? Parameters { get; set; }
        public DateTime? ScheduledTime { get; set; }
        public DateTime CreationTime { get; set; }
    }

    /// <summary>
    /// 通知发送事件
    /// </summary>
    public class NotificationSentEto
    {
        public Guid Id { get; set; }
        public Guid? TenantId { get; set; }
        public string Title { get; set; } = string.Empty;
        public Domain.Shared.Notifications.NotificationType Type { get; set; }
        public Domain.Shared.Notifications.NotificationChannel Channel { get; set; }
        public Guid? RecipientId { get; set; }
        public string? RecipientEmail { get; set; }
        public Guid? SenderId { get; set; }
        public DateTime SentTime { get; set; }
        public string? ExternalId { get; set; }
    }

    /// <summary>
    /// 通知送达事件
    /// </summary>
    public class NotificationDeliveredEto     {
        public Guid Id { get; set; }
        public Guid? TenantId { get; set; }
        public Domain.Shared.Notifications.NotificationType Type { get; set; }
        public Domain.Shared.Notifications.NotificationChannel Channel { get; set; }
        public Guid? RecipientId { get; set; }
        public string? RecipientEmail { get; set; }
        public DateTime DeliveredTime { get; set; }
        public string? ExternalId { get; set; }
    }

    /// <summary>
    /// 通知已读事件
    /// </summary>
    public class NotificationReadEto     {
        public Guid Id { get; set; }
        public Guid? TenantId { get; set; }
        public Domain.Shared.Notifications.NotificationType Type { get; set; }
        public Domain.Shared.Notifications.NotificationChannel Channel { get; set; }
        public Guid? RecipientId { get; set; }
        public DateTime ReadTime { get; set; }
    }

    /// <summary>
    /// 通知失败事件
    /// </summary>
    public class NotificationFailedEto     {
        public Guid Id { get; set; }
        public Guid? TenantId { get; set; }
        public string Title { get; set; } = string.Empty;
        public Domain.Shared.Notifications.NotificationType Type { get; set; }
        public Domain.Shared.Notifications.NotificationChannel Channel { get; set; }
        public Guid? RecipientId { get; set; }
        public string? RecipientEmail { get; set; }
        public DateTime FailedTime { get; set; }
        public string FailureReason { get; set; } = string.Empty;
        public int RetryCount { get; set; }
        public bool WillRetry { get; set; }
        public DateTime? NextRetryTime { get; set; }
    }

    /// <summary>
    /// 通知取消事件
    /// </summary>
    public class NotificationCancelledEto     {
        public Guid Id { get; set; }
        public Guid? TenantId { get; set; }
        public string Title { get; set; } = string.Empty;
        public Domain.Shared.Notifications.NotificationType Type { get; set; }
        public Guid? RecipientId { get; set; }
        public string? Reason { get; set; }
        public DateTime CancelledTime { get; set; }
    }

    /// <summary>
    /// 通知模板创建事件
    /// </summary>
    public class NotificationTemplateCreatedEto     {
        public Guid Id { get; set; }
        public Guid? TenantId { get; set; }
        public string Name { get; set; } = string.Empty;
        public string DisplayName { get; set; } = string.Empty;
        public Domain.Shared.Notifications.TemplateType Type { get; set; }
        public NotificationType NotificationType { get; set; }
        public string ContentTemplate { get; set; } = string.Empty;
        public string? SubjectTemplate { get; set; }
        public bool IsSystem { get; set; }
        public bool SupportsMultiLanguage { get; set; }
        public string DefaultLanguage { get; set; } = string.Empty;
        public DateTime CreationTime { get; set; }
    }

    /// <summary>
    /// 通知模板更新事件
    /// </summary>
    public class NotificationTemplateUpdatedEto     {
        public Guid Id { get; set; }
        public Guid? TenantId { get; set; }
        public string Name { get; set; } = string.Empty;
        public string DisplayName { get; set; } = string.Empty;
        public string ContentTemplate { get; set; } = string.Empty;
        public string? SubjectTemplate { get; set; }
        public string Version { get; set; } = string.Empty;
        public DateTime LastModificationTime { get; set; }
    }

    /// <summary>
    /// 通知模板删除事件
    /// </summary>
    public class NotificationTemplateDeletedEto     {
        public Guid Id { get; set; }
        public Guid? TenantId { get; set; }
        public string Name { get; set; } = string.Empty;
        public string DisplayName { get; set; } = string.Empty;
        public DateTime DeletionTime { get; set; }
    }

    /// <summary>
    /// 通知订阅变更事件
    /// </summary>
    public class NotificationSubscriptionChangedEto     {
        public Guid Id { get; set; }
        public Guid? TenantId { get; set; }
        public Guid UserId { get; set; }
        public string UserName { get; set; } = string.Empty;
        public string? EmailAddress { get; set; }
        public string? PhoneNumber { get; set; }
        public bool IsEnabled { get; set; }
        public List<Domain.Shared.Notifications.NotificationType> SubscribedTypes { get; set; } = new();
        public List<Domain.Shared.Notifications.NotificationChannel> EnabledChannels { get; set; } = new();
        public string ChangeType { get; set; } = string.Empty; // Created, Updated, Deleted
        public DateTime ChangeTime { get; set; }
    }

    /// <summary>
    /// 通知批次创建事件
    /// </summary>
    public class NotificationBatchCreatedEto     {
        public Guid Id { get; set; }
        public Guid? TenantId { get; set; }
        public string Name { get; set; } = string.Empty;
        public string BatchCode { get; set; } = string.Empty;
        public Domain.Shared.Notifications.NotificationBatchType Type { get; set; }
        public NotificationType NotificationType { get; set; }
        public Domain.Shared.Notifications.NotificationPriority Priority { get; set; }
        public int TotalRecipients { get; set; }
        public Guid? SenderId { get; set; }
        public string? SenderName { get; set; }
        public DateTime? ScheduledTime { get; set; }
        public DateTime CreationTime { get; set; }
    }

    /// <summary>
    /// 通知批次开始事件
    /// </summary>
    public class NotificationBatchStartedEto     {
        public Guid Id { get; set; }
        public Guid? TenantId { get; set; }
        public string Name { get; set; } = string.Empty;
        public string BatchCode { get; set; } = string.Empty;
        public int TotalRecipients { get; set; }
        public DateTime StartedTime { get; set; }
    }

    /// <summary>
    /// 通知批次完成事件
    /// </summary>
    public class NotificationBatchCompletedEto     {
        public Guid Id { get; set; }
        public Guid? TenantId { get; set; }
        public string Name { get; set; } = string.Empty;
        public string BatchCode { get; set; } = string.Empty;
        public int TotalRecipients { get; set; }
        public int SentCount { get; set; }
        public int DeliveredCount { get; set; }
        public int FailedCount { get; set; }
        public double SuccessRate { get; set; }
        public DateTime CompletedTime { get; set; }
        public TimeSpan? Duration { get; set; }
    }

    /// <summary>
    /// 通知批次取消事件
    /// </summary>
    public class NotificationBatchCancelledEto     {
        public Guid Id { get; set; }
        public Guid? TenantId { get; set; }
        public string Name { get; set; } = string.Empty;
        public string BatchCode { get; set; } = string.Empty;
        public int TotalRecipients { get; set; }
        public int SentCount { get; set; }
        public int DeliveredCount { get; set; }
        public string? Reason { get; set; }
        public DateTime CancelledTime { get; set; }
    }

    /// <summary>
    /// 通知统计事件
    /// </summary>
    public class NotificationStatisticsEto     {
        public Guid? TenantId { get; set; }
        public DateTime StatisticsDate { get; set; }
        public int TotalNotifications { get; set; }
        public int SentNotifications { get; set; }
        public int DeliveredNotifications { get; set; }
        public int FailedNotifications { get; set; }
        public int ReadNotifications { get; set; }
        public Dictionary<Domain.Shared.Notifications.NotificationType, int> NotificationsByType { get; set; } = new();
        public Dictionary<Domain.Shared.Notifications.NotificationChannel, int> NotificationsByChannel { get; set; } = new();
        public Dictionary<Domain.Shared.Notifications.NotificationPriority, int> NotificationsByPriority { get; set; } = new();
        public Dictionary<Domain.Shared.Notifications.NotificationStatus, int> NotificationsByStatus { get; set; } = new();
        public double AverageDeliveryTimeMs { get; set; }
        public double SuccessRate { get; set; }
        public double ReadRate { get; set; }
        public DateTime GeneratedTime { get; set; }
    }
}